<?php

namespace App\Containers\AppSection\Moderation\Tasks;

use App\Containers\AppSection\Moderation\Data\Repositories\ModerationRepository;
use App\Containers\AppSection\Moderation\Models\Moderation;
use App\Ship\Exceptions\BadRequestException;
use App\Ship\Parents\Tasks\Task;
use Exception;

class SendToModerationTask extends Task
{

    protected ModerationRepository $repository;

    public function __construct(
        ModerationRepository $repository
    )
    {
        $this->repository = $repository;
    }

    public function run($data): Moderation
    {
        try {
            return $this->repository->create($data);
        } catch (Exception $exception) {
            throw new BadRequestException();
        }
    }
}
